﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint;

namespace PeopleEditor
{
    public class CustPeopleFind : Microsoft.SharePoint.WebControls.PeopleEditor
    {       
        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);
            base.DialogTitle = "Custom People Editor";
            bool loadAdminSettings = false;

            //Load the settings
            PeoplePickerSettings _commonSettings = Common.CommonPeoplePickerSettings(SPContext.Current.Site.WebApplication);
            PeoplePickerSettings _adminSettings = Common.AdminPeoplePickerSettings(SPContext.Current.Site.WebApplication);

            //Check if the user is an entitled admin
            if (_adminSettings.TypeOfAdmin == PeoplePickerSettings.AdminType.SiteAdmin && SPContext.Current.Web.UserIsSiteAdmin)
            {
                loadAdminSettings = true;
            }
            if (_adminSettings.TypeOfAdmin == PeoplePickerSettings.AdminType.WebAdmin && SPContext.Current.Web.UserIsWebAdmin)
            {
                loadAdminSettings = true;
            }

            //Load the appropriate SelectionSet
            if (loadAdminSettings)
            {
                this.SelectionSet = _adminSettings.SelectionSet;
            }
            else
            {
                this.SelectionSet = _commonSettings.SelectionSet;
            }
        }
    }
}
